package com.flyduck.vueshop.system.remote.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.flyduck.vueshop.common.core.utils.BeanUtils;
import com.flyduck.vueshop.system.remote.service.RemoteMenuService;
import com.flyduck.vueshop.system.constant.SysConstant;
import com.flyduck.vueshop.system.vo.RemoteMenuRespVO;
import com.flyduck.vueshop.system.entity.SysMenu;
import com.flyduck.vueshop.system.manager.SysPermissionCacheManager;
import com.flyduck.vueshop.system.mapper.SysMenuMapper;
import com.flyduck.vueshop.system.mapper.SysRoleMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * SysUserApiServiceImpl
 * </p>
 *
 * @author flyduck
 * @since 2024-07-09
 */
@Service
public class RemoteMenuServiceImpl implements RemoteMenuService {

    @Resource
    private SysRoleMapper sysRoleMapper;
    @Resource
    private SysMenuMapper sysMenuMapper;
    @Resource
    private SysPermissionCacheManager sysPermissionCacheManager;

    @Override
    public List<String> getPermissionListByUserId(Long userId) {
        return sysPermissionCacheManager.getPermissionListByUserId(userId);
    }

    @Override
    public List<RemoteMenuRespVO> getEnableMenuListByUserId(Long userId) {
        List<SysMenu> sysMenuList = sysMenuMapper.getEnableMenuListByUserId(userId);
        List<RemoteMenuRespVO> remoteMenuRespVOList = BeanUtils.toBeanList(sysMenuList, RemoteMenuRespVO.class);
        return remoteMenuRespVOList;
    }

    @Override
    public List<RemoteMenuRespVO> getEnableMenuList() {
        List<SysMenu> sysMenuList = sysMenuMapper.selectList(
                new LambdaQueryWrapper<SysMenu>()
                        .eq(SysMenu::getStatus, SysConstant.CommonStatus.ENABLE.getCode())
                        .orderByDesc(SysMenu::getSortOrder)
        );
        List<RemoteMenuRespVO> remoteMenuRespVOList = BeanUtils.toBeanList(sysMenuList, RemoteMenuRespVO.class);
        return remoteMenuRespVOList;
    }
}
